package com.brave.manager.service;

import com.brave.manager.dao.StudentDao;
import com.brave.manager.domian.Student;

public class StudentService {
    private StudentDao StudentDao = new StudentDao();

    public boolean isExists(String id) {
        Student[] stus = StudentDao.findAllStudent();
        boolean Existe = false;
        for (int i = 0; i < stus.length; i++) {
            Student stu = stus[i];
            if (stu != null && stu.getId().equals(id)) {
                Existe = true;
                break;
            }
        }
        return Existe;
    }

    public boolean addStudent(Student stu) {
        return StudentDao.addStudent(stu);
    }

    public Student[] findAllStudent() {
        Student[] allStudent = StudentDao.findAllStudent();
        boolean res = false;
        for (int i = 0; i < allStudent.length; i++) {
            Student stu = allStudent[i];
            if (stu != null) {
                res = true;
                break;
            }
        }
        if (res) {
            return allStudent;
        } else {
            return null;
        }

    }

    public void deleteStudent(String id) {
        StudentDao.deleteStudent(id);
    }

    public void updateStudent(String id, Student stu) {
        StudentDao.updateStudent(id,stu);
    }
}
